package start;

import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;

public class Aide extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JEditorPane html;
	JFrame parent ;
	public Aide(){
		this.setVisible(true);
		this.setSize(700, 600);
		setLocationRelativeTo(parent);
		this.setTitle("Aide");
		//this.setIconImage(sary(this,"png16x16/calendar.png"));
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		try {
		    URL url = null;
		    // System.getProperty("user.dir") +
		    // System.getProperty("file.separator");
		    String path = null;
		    try {
			path = "icon/Help.html";
			url = getClass().getResource(path);
	            } catch (Exception e) {
			System.err.println("Failed to open " + path);
			url = null;
	            }
		    
	            if(url != null) {
	                html = new JEditorPane(url);
	                
	                html.setEditable(false);
	                html.addHyperlinkListener(createHyperLinkListener());

			JScrollPane scroller = new JScrollPane();
			JViewport vp = scroller.getViewport();
			vp.add(html);
	                this.add(scroller, BorderLayout.CENTER);
	            }
	        } catch (MalformedURLException e) {
	            System.out.println("Malformed URL: " + e);
	        } catch (IOException e) {
	            System.out.println("IOException: " + e);
	        }
	}
	
	
	 public HyperlinkListener createHyperLinkListener() {
			return new HyperlinkListener() {
			    public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				    if (e instanceof HTMLFrameHyperlinkEvent) {
					((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent(
					    (HTMLFrameHyperlinkEvent)e);
				    } else {
					try {
					    html.setPage(e.getURL());
					} catch (IOException ioe) {
					    System.out.println("IOE: " + ioe);
					}
				    }
				}
			    }
			};
		    }
	 void updateDragEnabled(boolean dragEnabled) {
	        html.setDragEnabled(dragEnabled);
	    }
	//url des images
		public static Image sary(JFrame j,String s){
			Toolkit toolkit = Toolkit.getDefaultToolkit();
			URL url = j.getClass().getResource(s);
			Image image = toolkit.getImage(url);
			return image;
		}
	//LOOK AND FEEL
		static
			 {
				 try
			     {
			      	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			     }
				 catch (Exception exception)
			      {
			      	exception.printStackTrace();
			      }
			 }
	 
	 public static void main(String[] args) {
			new Aide();
			//demo.mainImpl();
		    }
	 
	 

}
